<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Register_model extends Model{
    function Register_model(){
        parent::Model();
    }

    function form(){
        $this->load->helper('form');

        $data['username'] = array(
            'name' => 'usernameReg',
            'id' => 'usernameReg',
        );


        $data['password'] = array(
            'name' => 'passwordReg',
            'id' => 'passwordReg',
            'type' => 'password'
        );


        $data['nama'] = array(
            'name' => 'namaReg',
            'id' => 'namaReg',
        );


        $data['alamat'] = array(
            'name' => 'alamatReg',
            'id' => 'alamatReg',
        );

        $data['tgllahir'] = array(
            'name' => 'tgllahirReg',
            'id' => 'tgllahirReg',
        );

        $data['gaji'] = array(
            'name' => 'gajiReg',
            'id' => 'gajiReg',
        );

        $data['tglmasuk'] = array(
            'name' => 'tglmasukReg',
            'id' => 'tglmasukReg',
        );

        $data['nohp'] = array(
            'name' => 'nohpReg',
            'id' => 'nohpReg',
        );

        $data['submit'] = array(
            'name' => 'submitReg',
            'id' => 'submitReg',
            'value' => 'Daftar',
        );

        return $data;
    }

    function daftar(){
        $this->load->library('reg_validation');
        $username = $this->input->post('usernameReg');
        $opassword = $this->input->post('passwordReg');
        $password = md5($opassword);
        $nama = $this->input->post('namaReg');
        $alamat = $this->input->post('alamatReg');
        $gaji = $this->input->post('gajiReg');
        $tgllahir = $this->input->post('tgllahirReg');
        $tglmasuk = $this->input->post('tglmasukReg');
        $nohp = $this->input->post('nohpReg');
        //echo $username;
        if ($this->reg_validation->validate($username, $opassword, $nama, $alamat, $gaji, $tgllahir, $tglmasuk, $nohp)){
            
            $data = array(
                'username' => $username,
                'password' => $password,
                'nama' => $nama,
                'alamat' => $alamat,
                'gaji' => $gaji,
                'tgl_lahir' => $tgllahir,
                'tgl_masuk' => $tglmasuk,
                'no_hp' => $nohp,
            );

            $this->db->insert('pegawai',$data);
            redirect(base_url(). index_page().'/admin/register/success', 'location');
        }
        else{
            redirect(base_url(). index_page().'/admin/register/fail', 'location');
        }
    }
}
?>
